package cn.sz.dzy.common.enums;

public enum StatusCode {
    OK(0,"正常"),
    OtherError(1,"其他未知错误"),
    DeviceBusy(2,"设备忙"),
    DeviceError(3,"设备错"),
    InvalidOperation(4,"无效操作"),
    InvalidXMLFormat(5,"XML格式无效"),
    InvalidXMLContent(6,"XML内容无效"),
    InvalidJSONFormat(7,"JSON格式无效"),
    InvalidJSONContent(8,"JSON内容无效"),
    Reboot(9,"重启"),
    ;


    private int code;

    private String name;

    StatusCode(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public static String getNameByCode(Integer code){
        StatusCode[] values = StatusCode.values();
        for(StatusCode statusCode:values){
            if(code.equals(statusCode.getCode())){
                return statusCode.getName();
            }
        }
        return null;
    }

    public static String getCodeByName(String name){
        StatusCode[] values = StatusCode.values();
        for(StatusCode statusCode:values){
            if(name.equals(statusCode.getName())){
                return String.valueOf(statusCode.getCode());
            }
        }
        return null;
    }
}
